home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / SciCalc1.1 / Source / fmttst.c < prev    next >
Text File  |  1994-04-24  |  2KB  |  95 lines

  1. #import <string.h>      /* Standard C string operator function prototypes */
  2. #include <stdio.h>       /* Standard I/O functions and definitions */
  3. #include <math.h>    /* Standard C math library function prototypes */
  4.  
  5.  
  6. void STR_OctalToBinary (char*, char*);
  7. void STR_BinaryToOctal (char*, char*);
  8.  
  9. int main()
  10.  
  11. {   /* Local Variables */
  12.     double quadword;
  13.     float  flword;
  14.     long   ilword, *ilwptr;
  15.     short  word;
  16.     int    fmtlen;
  17.     char   byte;
  18.     char fmtstr[128];
  19.     char outstr[128];
  20.     char *fmtptr;
  21.  
  22.  
  23. printf("Enter Quadword Value: ");
  24. scanf("%lf",&quadword);
  25. printf("%f\n", quadword);
  26.  
  27. printf("Enter Longword Value: ");
  28. scanf("%x",&ilword);
  29. printf("%X\n", ilword);
  30.  
  31. printf("Enter Word Value: ");
  32. scanf("%hx",&word);
  33. printf("%X\n", word);
  34.  
  35. printf("Enter Byte Value: ");
  36. scanf("%hx",(short*)&byte);
  37. printf("%X\n", byte);
  38.  
  39. printf("Enter Format Length: ");
  40. scanf("%d", &fmtlen);
  41.  
  42. flword = quadword;
  43. ilword = quadword;
  44. ilwptr = (long*) &quadword;
  45. word   = quadword;
  46. byte   = quadword;
  47.  
  48. printf("DECIMAL:\n");
  49. printf("\tfmtlen:%.*f\n", fmtlen,quadword);
  50. printf("\tquadword:%f\n", quadword);
  51. printf("\tlongword:%f\n", flword);
  52. printf("\tword    :%d\n", word);
  53. printf("\tbyte    :%d\n", byte);
  54.  
  55. #if 0
  56. printf("HEXIDECIMAL:\n");
  57. printf("\tquadword:%8.8X,%8.8X\n", *ilwptr,*(ilwptr+1));
  58. printf("\tlongword:%8.8X\n", ilword);
  59. printf("\tword    :%4.4X\n", (unsigned short) word);
  60. printf("\tbyte    :%2.2X\n", (unsigned char) byte);
  61.  
  62. printf("OCTAL:\n");
  63. printf("\tquadword:%11.11o,%11.11o\n", *ilwptr,*(ilwptr+1));
  64. printf("\tlongword:%11.11o\n", ilword);
  65. printf("\tword    :%6.6o\n", (unsigned short) word);
  66. printf("\tbyte    :%3.3o\n", (unsigned char) byte);
  67.  
  68. printf("BINARY:\n");
  69. sprintf(fmtstr,"%11.11o%11.11o", *ilwptr,*(ilwptr+1));
  70. STR_OctalToBinary (fmtstr, outstr);
  71. printf("\tquadword:%s\n", outstr);
  72. STR_BinaryToOctal (outstr, fmtstr);
  73. printf("\t        :(%s)\n", fmtstr);
  74.  
  75. sprintf(fmtstr, "%11.11o", ilword);
  76. STR_OctalToBinary (fmtstr, outstr);
  77. printf("\tlongword:%s\n", outstr);
  78. STR_BinaryToOctal (outstr, fmtstr);
  79. printf("\t        :(%s)\n", fmtstr);
  80.  
  81. sprintf(fmtstr, "%6.6o", (unsigned short) word);
  82. STR_OctalToBinary (fmtstr, outstr);
  83. printf("\tword    :%s\n", outstr);
  84. STR_BinaryToOctal (outstr, fmtstr);
  85. printf("\t        :(%s)\n", fmtstr);
  86.  
  87. sprintf(fmtstr, "%3.3o", (unsigned char) byte);
  88. STR_OctalToBinary (fmtstr, outstr);
  89. printf("\tbyte    :%s\n", outstr);
  90. STR_BinaryToOctal (outstr, fmtstr);
  91. printf("\t        :(%s)\n", fmtstr);
  92. #endif
  93. return 0;
  94. }
  95.